from django import template
from django.template import Context, Template

register = template.Library()

@register.tag(name="repeat")
def do_repeat(parser, token):
    nodelist = parser.parse(('endrepeat',))
    tag_name, data = token.split_contents()
    parser.delete_first_token()
    return RepeatNode(data, nodelist)

class RepeatNode(template.Node):
    def __init__(self, data, nodelist):
        self.data = template.Variable(data)
	self.nodelist = nodelist
    def render(self, context):
        output = ""
        for d in iter(self.data.resolve(context)):
            output += self.nodelist.render(Context(d))
        return output
